﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
		<!-- ace styles -->
<link href="plugins/js/bootstrap-3.3.2-dist/css/bootstrap.min.css" rel="stylesheet" />
<script src='static/js/jquery-2.1.3.min.js'></script>
<script type="text/javascript" src="plugins/js/bootstrap-3.3.2-dist/js/bootstrap.min.js"></script>
<script type="text/javascript" src="plugins/js/jquery.bootstrap.min.js"></script>
<script type="text/javascript" src="static/js/layer.js"></script>
<script type="text/javascript" src="plugins/jquery.form.js"></script>
<script type="text/javascript" src="static/js/jquery.twbsPagination.min.js"></script>
<link rel="stylesheet" href="static/css/layui.css" media="all">
<style type="text/css">
	td.center, th.center {
  	  text-align: center !important;
	}
</style>
<script type="text/javascript">
	$(function(){
		$(top.hangge());
		
		$('#pagination').twbsPagination({
			totalPages : ${pageResult.totalPage},
			startPage : ${pageResult.currentPage},
			visiblePages : 5,
			first : "首页",
			prev : "上一页",
			next : "下一页",
			last : "最后一页",
			onPageClick : function(event, page) {
				$("#currentPage").val(page);
				$("#searchForm").submit();
			}
		});
		//高级查询
		$("#query").click(function(){
			$("#currentPage").val(1);
			$("#searchForm").submit();
		})
		//添加数据字典
		$("#addSystemDictionaryBtn").click(function(){
			//清空表单内容
			$("#editForm")[0].reset();
			//清空隐藏id
			$("#systemDictionaryId").val("");
            $("#sn").attr("disabled",false)
			//打开摸态框
			$("#systemDictionaryModal").modal("show");
			
		})
		//编辑
		$("[class='edit_Btn']").click(function(){
			var json = $(this).data("json");
			//设置数据
			$("#systemDictionaryId").val(json.id);
			$("#title").val(json.title);
			$("#sn").val(json.sn);
            $("#sn").attr("disabled","disabled")
			$("#systemDictionaryModal").modal("show");
		})
		
		//点击保存
		$("#saveBtn").click(function(){
			$("#editForm").ajaxSubmit({
				success:function(data){
					$("#currentPage").val(1);
					$("#searchForm").submit();
				}
			})
		})
	});
    function delete2(id){
        layer.confirm('你确定要删除该选项？', {
            btn: ['删除','保留'] //按钮
        }, function(){
            $.ajax({
                type: "get",
                url: "systemDictionaryItem_delete1.do?id=" + id,
                async: true,
                success: function (data) {
                    layer.msg("已删除id：" + id + "返回值：" + data, {icon: 1});
                    window.location.reload();
                }
            });
        }, function(){
            layer.msg('已保留');
        });

    }
	</script>
</head>

<body>
<div>
	<div>
		<div class="page-header">
			<h3>数据字典管理</h3>
		</div>
			<!-- 提交分页的表单 -->
			<form id="searchForm" class="form-inline" method="post"
				action="<%=basePath%>/systemDictionary_list.do">
				<input type="hidden" name="currentPage" id="currentPage" value="" />
				 <div class="form-group"></div>
				<div class="form-group">
					<label>关键字</label>
					<input class="form-control" type="text" name="keyword"
						value="${qo.keyword}">
				</div>
				<div class="form-group">
					<button id="query" type="button" class="btn btn-success">
                        <span class="glyphicon glyphicon-search" aria-hidden="true"></span> <%--<i class="icon-search"</i>>--%>
                        查询</button>
					<a href="javascript:void(-1);" class="btn btn-success"
						id="addSystemDictionaryBtn"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>添加数据字典</a>
				</div>
			</form>
		</div>
		<table class="table table-hover">
				<thead>
					<tr>
						<th>名称</th>
						<th>编码</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
			<!-- 开始循环 -->
			<c:choose>
				<c:when test="${not empty pageResult.listData}">
					<c:if test="${true}">
						<c:forEach items="${pageResult.listData}" var="vo" varStatus="vs">
							<tr>
								<td>${vo.title}</td>
								<td>${vo.sn}</td>
								<td>
									<a href="javascript:void(-1);" class="edit_Btn" data-json='${vo.jsonstring}'>修改</a>
                                    <a href="javascript:void(-1);" onclick="delete2('${vo.id}')">删除</a> &nbsp;
								</td>
							</tr>
						</c:forEach>
					</c:if>
				</c:when>
				<c:otherwise>
					<tr class="main_info">
						<td colspan="100" class="center">没有相关数据</td>
					</tr>
				</c:otherwise>
			</c:choose>
		</tbody>
		</table>
		<div style="text-align: center;">
			<ul id="pagination" class="pagination"></ul>
		</div>
</div>
<div id="systemDictionaryModal" class="modal" tabindex="-1"
		role="dialog">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">编辑/增加</h4>
				</div>
				<div class="modal-body">
					<form id="editForm" class="form-horizontal" method="post"
						action="<%=basePath%>/systemDictionary_update.do" style="margin: -3px 118px">
						<input id="systemDictionaryId" type="hidden" name="id" value="" />
						<div class="form-group">
							<label class="col-sm-2 control-label">名称</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="title" name="title"
									placeholder="字典分类名称">
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">编码</label>
							<div class="col-sm-6">
								<input type="text" class="form-control" id="sn" name="sn"
									placeholder="字典分类编码">
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<a href="javascript:void(0);" class="btn btn-success" id="saveBtn"
						aria-hidden="true"><span class="glyphicon glyphicon-lock" aria-hidden="true"></span>保存</a> <a href="javascript:void(0);"
						class="btn" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>关闭</a>
				</div>
			</div>
		</div>
	</div>
</body>
</html>

